home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Champak 26 (Anniversary Edition)
/
Volume 26 [Anniversary Edition] - JOGO DISK .iso
/
DEPOSITO
/
REmovido
/
Esportes
/
LightningBreak.swf
/
scripts
/
frame_1
/
DoAction_4.as
< prev
next >
Wrap
Text File
|
2006-06-13
|
12KB
|
403 lines
_root.createEmptyMovieClip("g",100);
_root.createEmptyMovieClip("gstep",101);
CBall = function(id, mc)
{
this.id = id;
this.value = id;
this.mc = mc;
this.x = mc._x;
this.y = mc._y;
this.radius = _root.ballSize / 2;
this.mc.engine = this;
this.mc.defaultWidth = this.mc._width;
this.mc.defaultHeight = this.mc._height;
this.glass = 0;
this.glassSmashed = 0;
this.reset();
};
CBall.prototype.reset = function()
{
this.vx = 0;
this.vy = 0;
this.mc._x = this.x;
this.mc._y = this.y;
this.mc._xscale = 100;
this.mc._yscale = 100;
this.mc._alpha = 100;
this.mc._visible = true;
this.potted = -1;
this.glassSmashed = 0;
this.setGlass(0,1);
if(this.id == 1 && _root.lvl.colorSwap)
{
this.glass = 0;
this.colorSwap();
}
this.spot = 0;
this.mc.style.gotoAndStop(this.value + 1);
this.mc.style.label.gotoAndStop(this.value + 1);
this.mc.style.mc.gotoAndStop(this.glass + 1);
};
CBall.prototype.showLabel = function()
{
this.mc.style.label._visible = 1;
};
CBall.prototype.hideLabel = function()
{
this.mc.style.label._visible = 0;
};
CBall.prototype.initColorSwap = function()
{
this.value = this.id;
this.mc.style.gotoAndStop(this.value + 1);
this.mc.style.label.gotoAndStop(this.value + 1);
};
CBall.prototype.colorSwap = function()
{
if(this.id > 1)
{
this.value += 1;
if(this.value > 7)
{
this.value = 2;
}
this.mc.style.gotoAndStop(this.value + 1);
this.mc.style.label.gotoAndStop(this.value + 1);
}
};
CBall.prototype.setGlass = function(bool, force)
{
if(this.potted != -1 && !force)
{
return undefined;
}
this.glass = bool;
this.mc.style.mc.gotoAndStop(this.glass + 1);
};
CBall.prototype.smashGlass = function()
{
_root.snd.play("glass");
this.potted = 666;
this.spot = 1;
this.mc.style.mc.gotoAndStop("break");
this.glassSmashed = 1;
};
CBall.prototype.move = function()
{
if(this.potted > -1)
{
if(this.mc._alpha == 0)
{
return undefined;
}
if(this.glassSmashed)
{
return undefined;
}
var hole = _root.table.holes[this.potted];
var a = _global.v2d.math.unify({x:hole.x - this.x,y:hole.y - this.y});
var d = Math.sqrt(Math.pow(this.tx - hole.x,2) + Math.pow(this.ty - hole.y,2)) * 0.08;
this.vx *= 0.75;
this.vy *= 0.75;
this.vx += a.x * d;
this.vy += a.y * d;
this.x += this.vx;
this.y += this.vy;
this.vz += 0.1;
this.mc._width -= this.vz;
this.mc._height -= this.vz;
this.mc._alpha *= Math.pow(0.95,_global.dt);
if(this.mc._alpha > 2)
{
_root.stepRollTotalMovement += 1;
}
else
{
this.mc._alpha = 0;
this.mc._visible = false;
}
this.redraw();
return undefined;
}
this.col = {pos:1,type:0,pvx:this.vx,pvy:this.vy};
if(this.id == 8 && _root.lvl.breakout)
{
while(!(this.vx + this.vy))
{
this.vx = 5;
this.vy = 0;
this.ax = 0;
this.ay = 0;
}
if(Math.random() < 0.05)
{
this.ax += (Math.random() - 0.5) * 0.5;
this.ay += (Math.random() - 0.5) * 0.5;
}
this.vx += this.ax;
this.vy += this.ay;
this.tv = Math.sqrt(this.vx * this.vx + this.vy * this.vy);
this.vx = this.vx / this.tv * 6;
this.vy = this.vy / this.tv * 6;
}
this.tvx = this.vx * _global.dt;
this.tvy = this.vy * _global.dt;
this.tv = Math.sqrt(this.tvx * this.tvx + this.tvy * this.tvy);
if(this.id < 8)
{
_root.stepRollTotalMovement += this.tv;
}
this.tx = this.x + this.tvx;
this.ty = this.y + this.tvy;
if(this.glassSmashed == 1)
{
_root.stepRollTotalMovement += 2;
}
if(!(this.vx == 0 && this.vy == 0))
{
var colPosTemp;
for(var i in _root.table.hwalls)
{
var wall = _root.table.hwalls[i];
if(Math.min(this.y,this.ty) - this.radius <= wall.y0 && Math.max(this.y,this.ty) + this.radius >= wall.y0)
{
if(this.ty * wall.dir <= wall.y0 * wall.dir + this.radius && this.y * wall.dir >= wall.y0 * wall.dir + this.radius - 0.000001)
{
var hitX = this.x + (wall.y0 + this.radius * wall.dir - this.y) / this.tvy * this.tvx;
if(hitX >= wall.x0 && hitX <= wall.x1)
{
colPosTemp = 1 - (this.ty - (wall.y0 + this.radius * wall.dir)) / this.tvy;
if(colPosTemp < this.col.pos)
{
this.col.type = 1;
this.col.pos = colPosTemp;
this.col.pvx = this.tvx / _global.dt;
this.col.pvy = Math.abs(this.tvy * _root.table.flex) * wall.dir / _global.dt;
}
}
}
this.pointCollision({x:wall.x0,y:wall.y0});
this.pointCollision({x:wall.x1,y:wall.y1});
}
}
for(var i in _root.table.vwalls)
{
var wall = _root.table.vwalls[i];
if(Math.min(this.x,this.tx) - this.radius <= wall.x0 && Math.max(this.x,this.tx) + this.radius >= wall.x0)
{
if(this.tx * wall.dir <= wall.x0 * wall.dir + this.radius && this.x * wall.dir >= wall.x0 * wall.dir + this.radius - 0.000001)
{
var hitY = this.y + (wall.x0 + this.radius * wall.dir - this.x) / this.tvx * this.tvy;
if(hitY >= wall.y0 && hitY <= wall.y1)
{
colPosTemp = 1 - (this.tx - (wall.x0 + this.radius * wall.dir)) / this.tvx;
if(colPosTemp < this.col.pos)
{
this.col.type = 1;
this.col.pos = colPosTemp;
this.col.pvy = this.tvy / _global.dt;
this.col.pvx = Math.abs(this.tvx * _root.table.flex) * wall.dir / _global.dt;
}
}
}
this.pointCollision({x:wall.x0,y:wall.y0});
this.pointCollision({x:wall.x1,y:wall.y1});
}
}
var i = 0;
while(i < _root.ballsAmount + _root.breakout)
{
if(i != this.id)
{
this.sphereCollision(_root.balls[i]);
}
i++;
}
var i = 0;
while(i < 6)
{
if(_root.lids[i].closed)
{
this.pointCollision(_root.lidPoints[i]);
this.pointCollision(_root.lidPoints2[i]);
}
i++;
}
if(this.col.type == 1)
{
this.tx = this.x + this.tvx * this.col.pos;
this.ty = this.y + this.tvy * this.col.pos;
_root.snd.playEvent("reflect",this.tv * 0.05);
}
this.x = this.tx;
this.y = this.ty;
this.vx = this.col.pvx;
this.vy = this.col.pvy;
if(this.col.type == 2)
{
this.col.q.vx = this.col.qvx;
this.col.q.vy = this.col.qvy;
}
var f = 1 - 0.09 * (1 - Math.min(Math.abs(this.vx) + Math.abs(this.vy),3) * 0.33);
f = Math.pow(f * _root.lvl.friction,_global.dt);
this.vx *= f;
this.vy *= f;
this.redraw();
}
var hole;
var i = 0;
while(i < 6)
{
if(!_root.lids[i].closed)
{
hole = _root.table.holes[i];
if(Math.abs(this.tx - hole.x) <= hole.radius && Math.abs(this.ty - hole.y) <= hole.radius)
{
var d = Math.sqrt(Math.pow(this.tx - hole.x,2) + Math.pow(this.ty - hole.y,2));
if(d < hole.radius)
{
if(this.id != 8)
{
_root.pot(this.value,this.id);
}
else
{
this.spot = 1;
}
_root["h" + i].flash(this.value);
this.potted = i;
this.vz = 0;
}
}
}
i++;
}
};
CBall.prototype.sphereCollision = function(ball)
{
if(ball.potted != -1)
{
return undefined;
}
var a = ball.x - this.x;
var b = ball.y - this.y;
var c = Math.pow(this.tvx,2) + Math.pow(this.tvy,2);
var d = (this.tvy * a - this.tvx * b) / c * this.tv * -1;
var j = Math.sqrt(Math.pow(this.radius + ball.radius,2) - d * d);
if(!isNaN(j))
{
var p = (this.tvx * a + this.tvy * b) / c;
p *= 1 - j / (p * this.tv);
if(p < 0 && p > -0.000001)
{
p = 0;
}
if(p >= 0 && p < this.col.pos)
{
if(this.glass || ball.glass)
{
if(this.glass)
{
this.smashGlass();
}
if(ball.glass)
{
ball.smashGlass();
}
}
var qax;
var qay;
var pvx;
var pvy;
var colvx;
var colvy;
var pv;
var qv;
this.col.pos = p;
this.col.type = 2;
this.tx = this.x + this.tvx * p;
this.ty = this.y + this.tvy * p;
qax = ball.x - this.tx;
qay = ball.y - this.ty;
pvx = qay * -1;
pvy = qax;
colvx = this.vx - ball.vx;
colvy = this.vy - ball.vy;
var colv = Math.sqrt(colvx * colvx + colvy * colvy);
_root.snd.playEvent("ballcollide",colv / 50);
pv = (colvx * qay - colvy * qax) / (pvx * qay - pvy * qax);
this.col.q = ball;
qv = (colvy - pv * qax) / qay;
if(qv eq "NaN")
{
this.col.qvx = this.vx;
this.col.qvy = this.vy;
}
else
{
qax *= qv;
qay *= qv;
this.col.qvx = ball.vx + qax;
this.col.qvy = ball.vy + qay;
}
pvx *= pv;
pvy *= pv;
this.col.pvx = pvx;
this.col.pvy = pvy;
_root.collision(this,ball);
}
}
};
CBall.prototype.pointCollision = function(point)
{
var a = point.x - this.x;
var b = point.y - this.y;
var c = Math.pow(this.tvx,2) + Math.pow(this.tvy,2);
var d = (this.tvy * a - this.tvx * b) / c * this.tv * -1;
var j = Math.sqrt(this.radius * this.radius - d * d);
if(!isNaN(j))
{
var p = (this.tvx * a + this.tvy * b) / c;
p *= 1 - j / (p * this.tv);
if(p < 0 && p > -0.000001)
{
p = 0;
}
if(p >= 0 && p < this.col.pos)
{
this.col.pos = p;
this.col.type = 3;
this.tx = this.x + this.tvx * p;
this.ty = this.y + this.tvy * p;
var x1 = point.x - this.x;
var y1 = point.y - this.y;
var n1 = ((x1 * x1 + y1 * y1) / (this.tvx * x1 + this.tvy * y1) * this.tvy - y1) / x1;
var pvx = y1 * n1 * -1 - x1;
var pvy = x1 * n1 - y1;
var pv = this.tv * _root.table.flex / _global.dt / Math.sqrt(pvx * pvx + pvy * pvy);
this.col.pvx = pvx * pv;
this.col.pvy = Pvy * pv;
}
}
};
CBall.prototype.redraw = function()
{
this.mc._x = this.x;
this.mc._y = this.y;
};
CBall.prototype.setSpeed = function(vx, vy)
{
this.vx = vx;
this.vy = vy;
};
CBall.prototype.setPos = function(x, y)
{
this.x = x;
this.y = y;
this.redraw();
};
CBall.prototype.toString = function()
{
return "[CBall mc:" + this.mc + ", x:" + this.x + ", y:" + this.y + ", vx:" + this.vx + ", vy:" + this.vy + "]";
};